<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../../_template.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

    <ui:define name="centro">
        <h:form>
            <p:messages />
            <p:outputLabel value="Cadastro de Nota Fiscal - Consulta" 
                           style="font-size: x-large; width: 92%; margin-left: 25px" styleClass="labelInserir" />
            <p:fieldset styleClass="fieldsetInsert" style="width: 92%; margin-left: 25px">
                
                 <h:panelGrid columns="5" style="margin-bottom: 10px" >
                     <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 20px; text-align: left" value="Número" />
                        <p:inputText size="2" value="#{notaFiscalBean.notaFiscal.numero}" disabled="true"
                                     style="width: 100px; margin-left: 20px;text-align: right" 
                                     required="true" requiredMessage="Informe o número da Nota Fiscal" />
                    </h:panelGrid>
                     
                    <h:panelGrid columns="1" >
                        <h:outputLabel  style="margin-left: 20px; text-align: left" value="Data da Emissão"/>
                        <p:calendar pattern="dd/MM/yyyy" yearRange="c-100:c+100" navigator="true" readonlyInput="true" 
                                    style="margin-left: 20px;" maxdate="#{clienteBean.dataAtual}" 
                                    value="#{notaFiscalBean.notaFiscal.dataEmissao}" disabled="true"
                                    required="true" requiredMessage="Informe a data de Emissão." />
                    </h:panelGrid>
                    
                    <h:panelGrid columns="1" >
                        <h:outputLabel  style="margin-left: 20px; text-align: left" value="Tipo de Nota"/>
                        <p:selectOneMenu value="#{notaFiscalBean.notaFiscal.tipoNotaFiscal}" converter="entityConverter" disabled="true"
                                         required="true" requiredMessage="Informe o tipo de Nota Fiscal" style="margin-left: 20px">
                            <f:selectItem itemLabel="Escolha uma opção"/>
                            <f:selectItems value="#{tipoNotaFiscalBean.tipoNotasFiscais}" var="tipoNF" itemLabel="#{tipoNF.descricao}"/>
                        </p:selectOneMenu>
                    </h:panelGrid>
                
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 20px; text-align: left" value="Tipo de Cliente" />
                        <p:selectOneRadio id="tpCliente" value="#{notaFiscalBean.origem}" style="margin-left: 20px;" disabled="true" >
                            <f:selectItem itemLabel="PF"   itemValue="CLIENTE_PF"/>
                            <f:selectItem itemLabel="PJ"   itemValue="CLIENTE_PJ"/>
                            <f:ajax render="cliente" execute="tpCliente" listener="#{notaFiscalBean.buscaClientePorTipo}"/>
                        </p:selectOneRadio>  
                    </h:panelGrid>
                    
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 25px; text-align: left" value="Nome" />
                        <p:selectOneMenu id="cliente" value="#{notaFiscalBean.notaFiscal.cliente}" converter="entityConverter" disabled="true"
                                         style="margin-left: 25px; width: 250px">
                        <f:selectItem itemLabel="Escolha uma opção"/>
                        <f:selectItems value="#{notaFiscalBean.clientes}" var="lista" itemLabel="#{lista.nome}" />
                    </p:selectOneMenu>
                    </h:panelGrid>
                </h:panelGrid>
                
                <h:panelGrid columns="6" style="margin-bottom: 10px" >
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 20px; text-align: left" value="Valor Bruto" />
                        <p:inputText styleClass="moeda"  value="#{notaFiscalBean.notaFiscal.valorBruto}" style="margin-left: 20px; width: 150px; text-align: right"
                                 size="18" required="true" requiredMessage="Informe o valor bruto." disabled="true" >
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2" locale="pt_BR" />
                        </p:inputText>
                    </h:panelGrid>
                    
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 20px; text-align: left" value="Retenção" />
                        <p:inputText style="margin-left: 20px; width: 100px; text-align: right" value="#{notaFiscalBean.notaFiscal.retencao}" 
                                 size="10" required="true" requiredMessage="Informe a aliquota de retenção." disabled="true">
                              <f:convertNumber type="percent" />
                        </p:inputText>
                    </h:panelGrid>
                    
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 20px; text-align: left" value="Valor Retido" />
                        <p:inputText id="vlrRet" styleClass="moeda" size="18" disabled="true" style="margin-left: 20px; width: 150px; text-align: right"
                                 value="#{notaFiscalBean.notaFiscal.valorBruto * notaFiscalBean.notaFiscal.retencao}" >
                        <f:convertNumber minFractionDigits="2" maxFractionDigits="2" locale="pt_BR" />
                    </p:inputText>
                    </h:panelGrid>
                    
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 20px; text-align: left" value="Valor Líquido" />
                        <p:inputText id="vlrLiq" styleClass="moeda" size="18" disabled="true" style="margin-left: 20px; width: 150px; text-align: right"
                                 value="#{notaFiscalBean.notaFiscal.valorBruto - (notaFiscalBean.notaFiscal.valorBruto * notaFiscalBean.notaFiscal.retencao)}" >
                        <f:convertNumber minFractionDigits="2" maxFractionDigits="2" locale="pt_BR" />
                    </p:inputText>
                    </h:panelGrid>
                
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 20px; text-align: left" value="Imposto Único" />
                        <p:inputText style="margin-left: 20px; width: 100px; text-align: right" value="#{notaFiscalBean.notaFiscal.aliquotaImpostoUnico}" 
                                 size="10" required="true" requiredMessage="Informe a aliquota do imposto único." disabled="true">
                              <f:convertNumber type="percent" />
                        </p:inputText>
                    </h:panelGrid>
                    
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 20px; text-align: left" value="Valor do Imposto" />
                        <p:inputText id="vlrImp" styleClass="moeda" size="18" disabled="true"
                                 value="#{notaFiscalBean.notaFiscal.valorBruto * notaFiscalBean.notaFiscal.aliquotaImpostoUnico}"
                                 style="margin-left: 20px; width: 150px; text-align: right">
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2" locale="pt_BR"  />
                        </p:inputText>
                    </h:panelGrid>
                </h:panelGrid>
               
                <h:panelGrid columns="3" style="margin-bottom: 10px" >
                    <h:panelGrid columns="1" >
                        <h:outputLabel  style="margin-left: 20px; text-align: left" value="Data do Vencimento"/>
                        <p:calendar pattern="dd/MM/yyyy" yearRange="c-100:c+100" navigator="true" readonlyInput="true" 
                                    style="margin-left: 20px;" required="true" requiredMessage="Informe a data do vencimento." 
                                    value="#{notaFiscalBean.notaFiscal.dataVencimento}" disabled="true"/>
                    </h:panelGrid>
                    
                    <h:panelGrid columns="1" >
                        <h:outputLabel  style="margin-left: 20px; text-align: left" value="Conta para Crédito"/>
                        <p:selectOneMenu value="#{notaFiscalBean.notaFiscal.documento.conta}" converter="entityConverter"
                                     required="true" requiredMessage="Informe a conta para crédito." disabled="true"
                                     style="margin-left: 20px;">
                            <f:selectItem itemLabel="Escolha uma opção" noSelectionOption="true" />
                            <f:selectItems value="#{contaBean.contas}" var="conta" itemLabel="#{conta.nome}"/>
                        </p:selectOneMenu>
                    </h:panelGrid>
                    
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 20px; text-align: left" value="Grupo de Lançamento" />
                        <p:selectOneMenu value="#{notaFiscalBean.notaFiscal.documento.grupoLancamento}" converter="entityConverter" 
                                         style="margin-left: 20px; width: 200px" disabled="true"
                                         required="true" requiredMessage="Selecione o grupo de lançamento" >
                            <f:selectItem itemLabel="selecione"/>
                            <f:selectItems value="#{grupoLancamentoBean.grupoLancamentos}" var="grupo" itemLabel="#{grupo.descricao}"/>
                        </p:selectOneMenu>
                    </h:panelGrid>
                </h:panelGrid>
                <br/>
            </p:fieldset>
            <br/>
            <p:commandButton value="Voltar" action='#{notaFiscalBean.voltar}' immediate="true" ajax="false" 
                             style="margin-left: 20px; margin-top: 30px"/>
        </h:form>
    </ui:define>

</ui:composition>
